/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HDRToneMapper.java
 *
 * Created on 18.12.2008, 16:40:26
 */
package hdr_plugin;

import hdr_plugin.tonemapping.SimpleToneMapper;
import hdr_plugin.tonemapping.drago.DragoToneMapper;
import ij.ImagePlus;
import ij.WindowManager;
import ij.process.FloatProcessor;
import ij.process.ShortProcessor;

/**
 *
 * @author Alexander Heidrich <alexander.heidrich@hki-jena.de>
 */
public class HDRToneMapper extends java.awt.Frame {

    /** Creates new form HDRToneMapper */
    public HDRToneMapper() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        button1 = new java.awt.Button();
        button2 = new java.awt.Button();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });

        button1.setLabel("button1");
        button1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button1ActionPerformed(evt);
            }
        });
        add(button1, java.awt.BorderLayout.CENTER);

        button2.setLabel("button2");
        button2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                button2ActionPerformed(evt);
            }
        });
        add(button2, java.awt.BorderLayout.EAST);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Exit the Application */
    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        this.dispose();
    }//GEN-LAST:event_exitForm

    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button1ActionPerformed
        ImagePlus imp = WindowManager.getImage("Radiance Map");
        DragoToneMapper map = new DragoToneMapper(imp);
        FloatProcessor floatP = new FloatProcessor(imp.getWidth(), imp.getHeight(), map.map());
        ImagePlus newImage = new ImagePlus("Tone Mapped Image", floatP);
        newImage.show();
    }//GEN-LAST:event_button1ActionPerformed

    private void button2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button2ActionPerformed
        ImagePlus imp = WindowManager.getImage("Radiance Map");
        DragoToneMapper map = new DragoToneMapper(imp);
        double[] toConvert = map.map();
        short[] out = new short[toConvert.length];
        for (int i = 0; i < toConvert.length; i++) {
            out[i] = new Long(Math.round(toConvert[i] * 255)).shortValue();
            
        }
        ShortProcessor shortP = new ShortProcessor(imp.getWidth(), imp.getHeight(), out, null);
        ImagePlus newImage = new ImagePlus("Tone Mapped Image", shortP);
        newImage.show();
    }//GEN-LAST:event_button2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Button button1;
    private java.awt.Button button2;
    // End of variables declaration//GEN-END:variables
}
